package com.lanqiao.testwork;

public class Test29 {

	public static void main(String[] args) {
		test();

	}

	/**
	 * 3*3方阵对角线之和
	 */
	private static void test() {
		int num1 = 0,num2 = 0;
		int[][] a = new int[][] {{1,2,3},{4,5,6},{7,8,9}};
		for(int i = 0;i <a.length;i++) {
			for(int j = 0;j<a[i].length;j++) {
				if(i==j) {
					num1 += a[i][j];
				}
				if(i + j == 2) {
					num2 += a[i][j];
				}
			}
		}
		System.out.println("正对角线和为:"+num1);
		System.out.println("附对角线和为:"+num2);
	}

}
